import {RequestHandler} from 'express-serve-static-core';

const logger: RequestHandler = (req, res, next) => {
	const {hostname, url} = req;
	const realHost = req.header('x-real-host') || hostname;
	// 请求进入时间，分析页面缓存用
	req.__req_in_time = Date.now();
	req.realHost = realHost;
	// 暂时关闭该功能
	req.isLangDomainSite = false;
	req.href = `${req.protocol}://${realHost}${url}`;
	console.log(`[${hostname === realHost ? realHost : `${realHost}|${req.hostname}`}] ${url} 收到请求`);
	next();
};

export default logger;
